package com.zhoug.player3.core;


import android.text.TextUtils;

import com.zhoug.player3.core.utils.CalendarUtil;

import java.io.Serializable;

import androidx.annotation.Keep;

/**
 * <p>录像片段</p>
 * <p>
 * {
 * "size": 1204585608,
 * "beginTime": "2019-10-11T00:00:00.000+08:00",
 * "endTime": "2019-10-11T01:19:35.332+08:00"
 * }
 *
 * @author 张华洋 2018/9/17 15:50
 * @version V1.0.0
 * @name RecordSegment
 */
@Keep
public class RecordSegment implements Serializable, Comparable<RecordSegment> {
    /**
     * 录像片段开始时间
     * 格式 2019-10-11T00:00:00.000+08:00
     */
    private String BeginTime;
    /**
     * 录像片段结束时间
     * 格式 2019-10-11T00:00:00.000+08:00
     */
    private String EndTime;
    private long Size;
    /**
     * 录像片段开始时间{@link #BeginTime}转化为时间戳 毫秒
     */
    private long beginTimeMillis;
    private long endTimesMillis;
    private String thumbnailUrl;//缩率图


    public RecordSegment() {
    }


    public RecordSegment(long beginTimeMillis, long endTimesMillis) {
        this.beginTimeMillis = beginTimeMillis;
        this.endTimesMillis = endTimesMillis;
    }

    public RecordSegment(String beginTime, String endTime) {
        this.BeginTime = beginTime;
        this.EndTime = endTime;
    }

    public RecordSegment(String beginTime, String endTime, long size) {
        this.BeginTime = beginTime;
        this.EndTime = endTime;
        this.Size = size;
    }

    public String getBeginTime() {
        if (TextUtils.isEmpty(BeginTime) && beginTimeMillis > 0) {
            BeginTime = CalendarUtil.timeToyyyy_MM_dd_T_HH_mm_SSSZ(beginTimeMillis);
        }
        return BeginTime;
    }

    public void setBeginTime(String beginTime) {
        this.BeginTime = beginTime;
    }

    public String getEndTime() {
        if (TextUtils.isEmpty(EndTime) && endTimesMillis > 0) {
            EndTime = CalendarUtil.timeToyyyy_MM_dd_T_HH_mm_SSSZ(endTimesMillis);
        }
        return EndTime;
    }

    public void setEndTime(String endTime) {
        this.EndTime = endTime;
    }

    public long getSize() {
        if (Size == 0) {
            long begin = getBeginTimeMillis();
            long end = getEndTimesMillis();
            if (begin > 0 && end > 0) {
                Size = end - begin;
            }
        }
        return Size;
    }

    public void setSize(long size) {
        this.Size = size;
    }

    public long getBeginTimeMillis() {
        if (beginTimeMillis <= 0 && !TextUtils.isEmpty(BeginTime)) {
            beginTimeMillis = CalendarUtil.yyyy_MM_dd_T_HH_mm_SSSZToCalendar(BeginTime).getTimeInMillis();
        }
        return beginTimeMillis;
    }

    public void setBeginTimeMillis(long beginTimeMillis) {
        this.beginTimeMillis = beginTimeMillis;
    }

    public long getEndTimesMillis() {
        if (endTimesMillis <= 0 && !TextUtils.isEmpty(EndTime)) {
            endTimesMillis = CalendarUtil.yyyy_MM_dd_T_HH_mm_SSSZToCalendar(EndTime).getTimeInMillis();
        }
        return endTimesMillis;
    }

    public void setEndTimesMillis(long endTimesMillis) {
        this.endTimesMillis = endTimesMillis;
    }


    public String getThumbnailUrl() {
        return thumbnailUrl;
    }

    public void setThumbnailUrl(String thumbnailUrl) {
        this.thumbnailUrl = thumbnailUrl;
    }


    @Override
    public int compareTo(RecordSegment o) {
        long vs = getBeginTimeMillis() - o.getBeginTimeMillis();
        if (vs > 0) {
            return 1;
        } else if (vs < 0) {
            return -1;
        }
        return 0;
    }

}
